﻿using System;
using System.Collections.Generic;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Threading.Tasks;
using System.Windows;
using System.Threading;

namespace StressClient_UI
{
    /// <summary>
    /// Interaction logic for App.xaml
    /// </summary>
    public partial class App : Application
    {
        private static Mutex _InstanceMutex = null;
        protected override void OnStartup(StartupEventArgs e)
        {
            // check that there is only one instance of the control panel running...
            bool createdNew;
            _InstanceMutex = new Mutex(true, @"StressClient", out createdNew);
            if (!createdNew)
            {
                _InstanceMutex = null;
                MessageBox.Show("Only one StressClient instance allowed to run");
                Application.Current.Shutdown();
                return;
            }

            base.OnStartup(e);
        }
        protected override void OnExit(ExitEventArgs e)
        {
            if (_InstanceMutex != null)
                _InstanceMutex.ReleaseMutex();
            base.OnExit(e);
        }
    }
}
